package com.lyn.solitude.pluginhost.crash

import android.os.Process
import android.util.Log

/**
 *
 * @author longyn 2024/05/28
 * @version 1.0.0
 */
object PluginCrash : Thread.UncaughtExceptionHandler {

    const val TAG = "PluginCrash"

    @JvmStatic
    fun initialize() {
        Log.d(TAG,"initialize")
        Thread.setDefaultUncaughtExceptionHandler(this)
    }

    override fun uncaughtException(t: Thread, e: Throwable) {
        if ("main" == t.name) {
            e.printStackTrace()
            Log.d(TAG, "uncaughtException:" + e.message)
            Process.killProcess(Process.myPid())
        }
    }
}